Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data.search] Simplify poll logic and improve types #82545

Merged
merged 37 commits into from
Nov 24, 2020

Conversation

lukasolson
Copy link
Member

@lukasolson lukasolson commented Nov 3, 2020

Summary

This PR simplifies the async search polling observable and search strategy authoring.

Any new search strategy should be implementing a method that fetches partial data and formats it into a IKibanaSearchResponse.
pollSearch will periodically call this method, until response is complete or until an error or an abort have occurred.

For example:

export const customSearchStrategyProvider = (
  logger: Logger
): ISearchStrategy<CustomSearchStrategyRequest, CustomSearchStrategyResponse> => {
  return {
    search: ({ id, ...request }, options: IAsyncSearchOptions, { esClient, uiSettingsClient }) => {
      const search = async () => {
        const promise = id
          ? chekupOnSearch(...)
          : submitSearch(...);
        const response = await promise;
        return toCustomKibanaSearchResponse(response);
      };

      return pollSearch(search, options).pipe(tap((response) => (id = response.id)));
    },
  };
};

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@lukasolson lukasolson added Feature:Search Querying infrastructure in Kibana Project:AsyncSearch Background search, partial results, async search services. labels Nov 3, 2020
@lukasolson lukasolson requested a review from a team as a code owner November 3, 2020 23:47
@lukasolson lukasolson requested a review from a team November 3, 2020 23:47
@lukasolson lukasolson requested review from a team as code owners November 3, 2020 23:47
@lukasolson lukasolson self-assigned this Nov 3, 2020
@lukasolson lukasolson changed the title [data.search] Simplify poll logic and improve types [skip-ci] [data.search] Simplify poll logic and improve types Nov 3, 2020
@lukasolson lukasolson added the WIP Work in progress label Nov 3, 2020
@lizozom
Copy link
Contributor

lizozom commented Nov 4, 2020

@elasticmachine merge upstream

@lizozom lizozom changed the title [skip-ci] [data.search] Simplify poll logic and improve types [data.search] Simplify poll logic and improve types Nov 10, 2020
@lizozom lizozom added the release_note:skip Skip the PR/issue when compiling release notes label Nov 10, 2020
@lizozom
Copy link
Contributor

lizozom commented Nov 21, 2020

@elasticmachine merge upstream

@lizozom lizozom removed the WIP Work in progress label Nov 22, 2020
return es
.search({ ...request, params: dsl }, options, deps)
.pipe(mergeMap((esSearchRes) => queryFactory.parse(request, esSearchRes)));
return es.search({ ...request, params: dsl }, options, deps).pipe(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now shim totals in the responses in the route handler.
This means that internally, all strategies should work with the new format {value: 123, relation: 'eq'}.
We shimmed the types here to avoid test failures.

Copy link
Contributor

@patrykkopycinski patrykkopycinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIEM/Endpoint LGTM

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
data 603 599 -4
dataEnhanced 39 38 -1
total -5

Distributable file count

id before after diff
default 43051 43048 -3
oss 22580 22576 -4

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 977.4KB 973.5KB -3.9KB
dataEnhanced 36.3KB 35.2KB -1.1KB
total -5.0KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@lizozom lizozom merged commit f80da6c into elastic:master Nov 24, 2020
lizozom pushed a commit to lizozom/kibana that referenced this pull request Nov 24, 2020
* [Search] Add request context and asScoped pattern

* Update docs

* Unify interface for getting search client

* Update examples/search_examples/server/my_strategy.ts

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>

* Review feedback

* Fix checks

* Fix CI

* Fix security search

* Fix test

* Fix test for reals

* Fix types

* [data.search] Refactor search polling and improve types

* Fix & update tests & types

* eql totals

* doc

* Revert "eql totals"

This reverts commit 01e8a06.

* lint

* response type

* shim inside strategies

* shim for security

* fix eql params

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>
Co-authored-by: Liza K <liza.katz@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/server/index.ts
#	src/plugins/data/server/server.api.md
lizozom added a commit that referenced this pull request Nov 25, 2020
…84292)

* [data.search] Simplify poll logic and improve types (#82545)

* [Search] Add request context and asScoped pattern

* Update docs

* Unify interface for getting search client

* Update examples/search_examples/server/my_strategy.ts

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>

* Review feedback

* Fix checks

* Fix CI

* Fix security search

* Fix test

* Fix test for reals

* Fix types

* [data.search] Refactor search polling and improve types

* Fix & update tests & types

* eql totals

* doc

* Revert "eql totals"

This reverts commit 01e8a06.

* lint

* response type

* shim inside strategies

* shim for security

* fix eql params

Co-authored-by: Anton Dosov <dosantappdev@gmail.com>
Co-authored-by: Liza K <liza.katz@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/server/index.ts
#	src/plugins/data/server/server.api.md

* doc

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Search Querying infrastructure in Kibana Project:AsyncSearch Background search, partial results, async search services. release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants